Jump to the command else

Hi,

 

the problem is the code jump to the else command. What can I do ?

 

 


bu12 - Mon Feb 09 09:05:08 EST 2015

Re: Jump to the command else
Wolfgang Uhr - Mon Feb 09 10:53:56 EST 2015

Let me guess: You need an attribute named "Sonderzeichen"?

Re: Jump to the command else
Mathias Mamsch - Mon Feb 09 11:43:51 EST 2015

You should remove the else command. The problem will go away. Regards, Mathias

Re: Jump to the command else
GregM_dxler - Mon Feb 09 12:36:57 EST 2015

Your ad loop is flawed.

You try to loop through all the attribute definitions in the module.

You get the name of the first attribute definition in the module

If it is Sonderzeichen, it does something weird on trying to make a column and then halts.

If it is not (which is most likely the case) it prints Attribut exists and halts.

It never goes through the loop again.

Probably you want to not use halt, but break if you find the attribute, so it will skip the rest of the loop.

If you don't find the attribute (else statement) then you want to let the loop continue, so delete the halt.

Hope this helps,

Greg

Re: Jump to the command else
Mike.Scharnow - Tue Feb 10 05:21:11 EST 2015

Hello,

reading through your code again it is still not clear to me what you really want to achieve. The concepts of views with columns versus the concept of modules with AttributeDefinitions are mixed here.

A module knows which attributes exist for an object. So, if you have an object attribute definition with the name "Sonderzeichen", then every object in your module has an attribute "Sonderzeichen" which can store some value (perhaps true/false, if it is of type Boolean). So, this is about the storage of information.

A view on the other hand is about presentation of information. A module has a number of views, a view has a number of columns, each column may show the content of an attribute or something else. So, if you create a column (Column col = ...)  and say 'attribute (col, "Sonderzeichen")', then you tell DOORS "show me the content of the existing attribute "Sonderzeichen" in the column of the current view that I defined earlier."

What you currently do is to loop through all existing attributes and on certain conditions you create a column in a view. It does not sound to me like this is what you really want.

Either you want to create a new attribute if it does not exist or you want to show the existing attribute in the current view if it exists. The solution for your problem differs based on what you want.

Hope this helps,
Mike

Re: Jump to the command else
Mike.Scharnow - Tue Feb 10 07:51:07 EST 2015

yes, this approach is way better.

The only problem is that there is no function "exists" which checks for a column in a view. But you can write your own "exists" function.

Exercise for today: use part of the code below to do so. :-)

By the way: look up the usage of "insert", your variable "count" might not be initialized correctly.

Module mCurrent = current

Column colCurrent
bool bSonderzeichenColumnExists = false
Column colLastInView 

for colCurrent in mCurrent do {
  if (attrName colCurrent == "Sonderzeichen") {
    bSonderzeichenColumnExists = true
    print "ich bin schon da, sagte das Sonderzeichen\n"
  }
  colLastInView = colCurrent
}

if (!bSonderzeichenColumnExists) {
  // insert new column to the left of last column
  Column colNew = insert (colLastInView)
  width (colNew, 200)
  attribute (colNew, "Sonderzeichen")
}


 

Re: Jump to the command else
Mike.Scharnow - Tue Feb 10 08:49:19 EST 2015

well, let me guess: there is no attribute called "Sonderzeichen" in your module.

So, If that is the case, adding it to the view is not possible :-)

So, what do you need now? A check whether an attribute called "Sonderzeichen" exists in your module?

This is quite easy:

AttrDef adSonderzeichen = find (mCurrent, "Sonderzeichen")

if (null adSonderzeichen) {

  print "keine Sonderzeichen --> keine Spalte in der View\n"

} else {

  // insert here the above code if (!bSonderzeichenColumnExists...

}

Re: Jump to the command else
Mike.Scharnow - Tue Feb 10 09:29:23 EST 2015

Dear bu12,

*rant on*

I have the slight suspicion that you do not understand the code that you copy and paste, you just pick some random code lines and try to see what works. This is OK as long as you do it for yourself, but I would strongly suggest to invest some minutes in reading the code thoroughly before posting questions to the forum. 

*rant off*

Yes, of course, the variable col is not assigned. If you look at the DXL help, you see the following example:

Example 
This example inserts a new column 1 as a copy of the old column 1, if present: 

insert(column 1) 

So, what do we learn from this? The argument of the function "insert" is an existing column, so between the brackets, you need something that is to be copied.

Now, look at your code. You have a variable called "col". Look backwards, where this variable is used in your code. It is only mentioned in the first line "Column col", so it is only declared, not defined. So, there is nothing from which you make a copy. From my code you left out exactly the part that defined the variable that is used as parameter for "insert".

Try again...

Re: Jump to the command else
Mike.Scharnow - Wed Feb 11 04:01:02 EST 2015

The problem is line above "col = insert (col)". There you use col as a parameter for the insert function, but col has not been defined yet.

In my code, I wrote "colNew = insert (colLastInView)". colLastInView is defined in the loop "for column in module". In this loop, colLastInView is set to contain the last Column in the View. So, it contains a column -- and this column is taken as the parameter for the insert function. In your code, col is empty.

As an alternative, you could also write for example "col = insert (column 3)". Then the new column would be inserted left of the third column.

Alles klar?

Re: Jump to the command else
bu12 - Wed Feb 11 04:23:38 EST 2015

Mike.Scharnow - Wed Feb 11 04:01:02 EST 2015

The problem is line above "col = insert (col)". There you use col as a parameter for the insert function, but col has not been defined yet.

In my code, I wrote "colNew = insert (colLastInView)". colLastInView is defined in the loop "for column in module". In this loop, colLastInView is set to contain the last Column in the View. So, it contains a column -- and this column is taken as the parameter for the insert function. In your code, col is empty.

As an alternative, you could also write for example "col = insert (column 3)". Then the new column would be inserted left of the third column.

Alles klar?

I did it but the code give me the string "Sonderzeichen" as an error message -----> unknown attribute

 


}else (!bSonderzeichenColumnExists) {
 
  col = insert (column 1)
  attribute (col, "Sonderzeichen")
  width (col, 200)
 
}
  

Re: Jump to the command else
Mike.Scharnow - Wed Feb 11 04:28:49 EST 2015

bu12 - Wed Feb 11 04:23:38 EST 2015

I did it but the code give me the string "Sonderzeichen" as an error message -----> unknown attribute

 


}else (!bSonderzeichenColumnExists) {
 
  col = insert (column 1)
  attribute (col, "Sonderzeichen")
  width (col, 200)
 
}
  

Do you read my posts? I answered this question yesterday at 02:49 pm

Re: Jump to the command else
bu12 - Wed Feb 11 05:01:08 EST 2015

Mike.Scharnow - Wed Feb 11 04:28:49 EST 2015

Do you read my posts? I answered this question yesterday at 02:49 pm

I find a different mistake. It works now.